const path = require("path");
const os = require("os");
const fs = require("fs");

let filepath = path.resolve('./access.log')
let data = fs.readFileSync(filepath, 'utf-8')
let arr = data.split(os.EOL);
let cc = arr.reduce((v, t, i, arr) => {
    t.replace(/(.html|.js|.css)(?=\s)/, ($1) => {
        v[$1.slice(1)] ? v[$1.slice(1)]++ : v[$1.slice(1)] = 1
    })
    return v;
}, {});
let bb = arr.reduce((v, t, i, arr) => {
    t.replace(/(.gif|.png|.jpg)(?=\s)/, ($1) => {
        v[$1.slice(1)] ? v[$1.slice(1)]++ : v[$1.slice(1)] = 1
    })
    return v;
}, {});
let aa = arr.reduce((v, t, i, arr) => {
    t.replace(/(Chrome|Version|Firefox)(?=\/)/, ($1) => {
        v[$1] ? v[$1]++ : v[$1] = 1
    })
    return v;
}, {});

let fil = path.resolve('./index.html');
let _data = `<div>` + `html:${cc.html}` + `</div>` + `<div>` + `js:${cc.js}` + `</div>` + `<div>` + `css:${cc.css}` + `</div>` +
    `<div>` + `jpg:${bb.jpg}` + `</div>` + `<div>` + `png:${bb.png}` + `</div>` + `<div>` + `gif:${bb.gif}` + `</div>` + `<div>` +
    `Chrome:${aa.Chrome}` + `</div>` + `<div>` + `Version:${aa.Version}` + `</div>` + `<div>` + `Firefox:${aa.Firefox}` + `</div>`
fs.writeFileSync(fil, _data);